//
//  SpringViewController.m
//  OCAnimation
//
//  Created by zhouLiHuan on 2017/2/17.
//  Copyright © 2017年 zhouLiHuan. All rights reserved.
//

#import "SpringViewController.h"

@interface SpringViewController ()

@end

@implementation SpringViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 200, 50, 30)];
    label.backgroundColor = [UIColor redColor];
    [self.view addSubview:label];
    
    CASpringAnimation *springAnim = [CASpringAnimation animationWithKeyPath:@"position.x"];
    springAnim.damping = 5; //阻尼系数
    springAnim.stiffness = 100; // 刚度系数 气质越大 变形越大 运动越快
    springAnim.mass = 1; //质量
    springAnim.initialVelocity = 0; //初始速度
    springAnim.fromValue = @(label.layer.position.x);
    springAnim.toValue = @(label.layer.position.x + 100);
    springAnim.autoreverses = YES;
    springAnim.repeatCount = NSIntegerMax;
    springAnim.duration = springAnim.settlingDuration;
    [label.layer addAnimation:springAnim forKey:springAnim.keyPath];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
